<?php

/*
 * This file is part of the phpems/phpems.
 *
 * (c) oiuv <i@oiuv.cn>
 *
 * 项目维护：oiuv(QQ:7300637) | 定制服务：火眼(QQ:278768688)
 *
 * This source file is subject to the MIT license that is bundled.
 */

class action extends app
{
    public function display()
    {
        $action = $this->ev->url(3);
        if (!method_exists($this, $action)) {
            $action = 'index';
        }
        $this->$action();
        exit;
    }

    private function add()
    {
        // 添加公告表单页面
        $this->tpl->display('notice_add');
    }

    private function insert()
    {
//        var_dump($_POST);
        $data = '';
        foreach ($_POST['msg'] as $val) {
            $data .= '<li>'.$val.'</li>';
        }
//        var_dump($data);

        $notice = new \Model\Notice;
        $notice->noticeuser = $_POST['noticeuser'];
        $notice->noticetime = $_POST['noticetime'];
        $notice->notice = $data;
//        var_dump($notice);

        $notice->save();
        // 回到更新公告页面
        $message = [
            'statusCode' => 200,
            'message' => '操作成功，正在转入目标页面',
            'callbackType' => 'forward',
            'forwardUrl' => 'index.php?core-master-notice',
        ];
        exit(json_encode($message));
    }

    private function index()
    {
        $res = \Model\Notice::orderBy('noticeid','desc')->get();
        $data = $res->toArray();
        $this->tpl->assign('data', $data);
        // 更新公告页面
        $this->tpl->display('notice');
    }
}
